package com.tjnu.losca.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjnu.losca.mapper.TeacherJournalMapper;
import com.tjnu.losca.pojo.TeacherJournal;
import com.tjnu.losca.service.TeacherJournalService;
import org.springframework.stereotype.Service;

@Service
public class TeacherJournalServiceImpl extends ServiceImpl<TeacherJournalMapper,TeacherJournal> implements TeacherJournalService {
    //查询函数
    @Override
    public IPage<TeacherJournal> getTeacherJournal(int pageNum, int pageSize,String teacher, String department)  throws Exception{
        QueryWrapper<TeacherJournal> wrapper=new QueryWrapper<>();
        System.out.println(teacher);
        System.out.println(department);
        //给tid和DepartmentId设置一个默认值-1，若等于-1，则表示查询全部
        if(teacher.equals("-1")&&!department.equals("-1")){
            wrapper.eq("department",department);
        }
        else if(!teacher.equals("-1")&&department.equals("-1")){
            wrapper.eq("teacher",teacher);
        }
        else if(teacher.equals("-1")&&department.equals("-1")){
            wrapper.like("teacher","");
        }
        else wrapper.eq("teacher",teacher)
                    .eq("department",department);

        return this.page(new Page<>(pageNum,pageSize),wrapper);
    }

    //删除函数
    @Override
    public boolean del(Integer id) {
        TeacherJournal teacherJournal = this.getById(id);
        //状态设置为1为逻辑删除
        teacherJournal.setStatus(1);
        return this.updateById(teacherJournal);
    }

    @Override
    public boolean recovery(Integer id) {
        TeacherJournal teacherJournal = this.getById(id);
        //状态恢复成0表示正常
        teacherJournal.setStatus(0);
        return this.updateById(teacherJournal);
    }


}
